package kr.hkit.powerjava.chapter24;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyFileStream {
	public static void main(String[] args) {
		BufferedInputStream fis = null;
		BufferedOutputStream fos = null;

		long start,end;
		try {
			fis = new BufferedInputStream(new FileInputStream("2263236.png"));
			fos =  new BufferedOutputStream(new FileOutputStream("22632361.png",false));			//append mode true 밑에 중복 쓰기 false 초기화 후 다시 쓰기
			start = System.currentTimeMillis();
			
			int c;
			while ((c = fis.read()) != -1) {
				System.out.printf("%s", (char) c);
				fos.write(c);

			
			}
			
			end = System.currentTimeMillis();
			System.out.println("걸린시간 " + (end-start));
			System.out.println("파일 존재");
		} catch (FileNotFoundException e) {
			System.out.format("%s%n", "파일이 존재하지 않음");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (Exception e) {
				}

			}
			if (fos != null) {
				try {
					fos.close();
				} catch (Exception e) {
				}
			}
		}
	}
}
